from skimage import io
import cv2
import matplotlib.pyplot as plt
import numpy as np

TRAINING_SAMPLES = 2000
TESTING_SAMPLES  = 800
IMAGE_WIDTH = 150
IMAGE_HEIGHT = 150

X_train = []; X_test = []
y_train = []; y_test = []

dir_base = 'Datasets/DogsCats/'

for i in range(1,TRAINING_SAMPLES // 2):
    for label in ('dog','cat'):
        name = dir_base+'train/'+label+'s/'+label+'.{}'.format(i)+'.jpg'
        try:
            image = cv2.imread(name,cv2.IMREAD_COLOR)
            img2 = cv2.resize(image,(IMAGE_WIDTH,IMAGE_HEIGHT))
            X_train.append(img2)        
            if label == 'dog':
                y_train.append(1)
            else:
                y_train.append(0)
        except:
            continue  
                 
for i in range(4001, 4001 + TESTING_SAMPLES // 2):
    for label in ('dog','cat'):
        name = dir_base+'validation/'+label+'s/'+label+'.{}'.format(i)+'.jpg'
        try:
            image = cv2.imread(name,cv2.IMREAD_COLOR)
            img2 = cv2.resize(image,(IMAGE_WIDTH,IMAGE_HEIGHT))
            X_test.append(img2)
            if label == 'dog':
                y_test.append(1)
            else:
                y_test.append(0)
        except:
            continue

X_train = np.array(X_train); y_train = np.array(y_train)
X_test = np.array(X_test); y_test = np.array(y_test)
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
  
X_train = X_train / 255   # values [0..1] improve results
X_test = X_test / 255
